﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;

namespace LOGIN
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void btnLog_Click1(object sender, ImageClickEventArgs e)
        {
            Session["name"] = this.txtName.Text;
            string strCn = "server=pc.hstc.cn;database=dhd2014112122;uid=2014112122;pwd=19950123";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {
                string UserName = this.txtName.Text.ToString();
                string UserPassword = this.txtPwd.Text.ToString();
                cn.Open();
                string strSql = "SELECT   Name, Password  FROM      Login  WHERE   (Name = N'" + txtName.Text + "') AND (Password = N'" + txtPwd.Text + "')";
                SqlCommand cmd = new SqlCommand(strSql, cn);
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    UserName = "SELECT   Name  FROM      Login";
                    UserPassword = "SELECT   Password  FROM      Login";
                    string peo = Request.QueryString["peo"];
                    if (rbStu.Checked)
                    {
                        Response.Redirect("Main_Stu.aspx");
                    }
                    else
                    {
                        Response.Redirect("Main_Tea.aspx");
                    }
                }
                else
                {
                    Response.Write("<script>alert('您填写的登录信息有误，请重新填写。');location.href='index.aspx';</script>");
                }


            }
            catch (Exception ex)
            {
                this.lblInfo.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }

        protected void btnReg_Click1(object sender, ImageClickEventArgs e)
        {
            string strCn = "server=pc.hstc.cn;database=dhd2014112122;uid=2014112122;pwd=19950123";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {
                string peo = Request.QueryString["peo"];
                if (rbStu.Checked)
                {
                    Response.Redirect("Register.aspx");
                }
                else
                {
                    Response.Write("<script>alert('对不起，教师没有注册功能，单击“确定”可直接返回。');location.href='index.aspx';</script>");
                }
            }
            catch (Exception ex)
            {
                this.lblInfo.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }
    }
}